package com.though.utils.tools;

import org.apache.commons.lang3.time.DateFormatUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtils {

	
	public static String dateFormat = "yyyyMMddHHmmss";
	
	public static String dateFormat_YYYYMMDD = "yyyyMMdd";
	
	public static String dateFormat_default = "yyyy-MM-dd HH:mm:ss";
	
	public static String dateFormatYYYYMMDD = "yyyy-MM-dd";
	
	public static String dateFormatYYYYMM = "yyyy-MM";
	
	
	
	/**
	 * 获取当前时间
	 * @return
	 */
	public static String getCurrentTime() {
		return DateFormatUtils.format(new Date(), dateFormat);
	}
	
	
	/**
	 * 获取当前时间的n小时前
	 * @return
	 */
	public static String getCurrentTimeBeforeOneHour(int n) {
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.HOUR_OF_DAY, n);
		return DateFormatUtils.format(new Date(), dateFormat);
	}


	/**
	 * long 时间转 String  20170101105001
	 * @param create_date
	 * @return
	 */
	public static String formatString(long time) {
		try {
			return DateFormatUtils.format(new SimpleDateFormat("yyyyMMddHHmmss").parse(String.valueOf(time)), dateFormat_default);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	/**
	 * 今天剩余秒数
	 * @return
	 */
	public static long getTodayurplusSecond() {
        long secondsLeftToday = 86400 - org.apache.commons.lang3.time.DateUtils.getFragmentInSeconds(Calendar.getInstance(), Calendar.DATE);
        return secondsLeftToday;
	}
}
